<template>
  <div>
    <div class="toggle-search">
      <div class="left-btn">
        <slot name="btn"></slot>
      </div>
      <div class="right-search">
        <a-input-search
          v-if="!isExpand"
          v-model="searchKey"
          :placeholder="placeholder"
          @search="changeValue"
        ></a-input-search>
        <div
          v-if="showExpand"
          class="expand-text"
          :class="{ 'expand-active': isExpand }"
          @click="handleExpand"
        >
          {{ isExpand ? '收起筛选' : '展开筛选' }}
        </div>
      </div>
    </div>
    <div v-show="isExpand" class="search-content">
      <div class="form-item-box">
        <slot />
      </div>
      <div class="action-btn-box">
        <div class="btn-locate">
          <a-button type="primary" @click="handleSearch">查询</a-button>
          <a-button class="ml-10" @click="handleReset">重置</a-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ToggleSearch',
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    value: {
      type: String,
      default: ''
    },
    isExpand: {
      type: Boolean,
      default: false
    },
    placeholder: {
      type: String,
      default: '请输入'
    },
    showExpand: {
      type: Boolean,
      default: true
    },
    searchValue: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      searchKey: ''
    }
  },
  methods: {
    async pwConfirm(pwd) {
      const res = await this.exportMethod(pwd)
      if (res.success) {
        this.$message.success('导出成功')
        this.$refs['pwd-valid'].close()
      }
    },
    handleExpand() {
      this.$emit('update:isExpand', !this.isExpand)
    },
    changeValue() {
      this.$emit('search', this.searchKey)
    },
    handleSearch() {
      this.$emit('search')
    },
    handleReset() {
      this.$emit('reset')
    }
  }
}
</script>

<style lang="less" scoped>
.toggle-search {
  display: flex;
  justify-content: space-between;
  .left-btn .ant-btn {
    margin-right: 10px;
  }
  .right-search {
    display: flex;
    .ant-input-search {
      width: 280px;
    }
    .expand-text {
      position: relative;
      cursor: pointer;
      padding: 0 16px;
      margin-left: 12px;
      text-align: center;
      line-height: 32px;
    }
    .expand-active {
      background-color: var(--edu-back-op-4);
      &::before {
        content: '';
        position: absolute;
        width: 100%;
        background: var(--edu-back-op-4);
        height: 11px;
        left: 0;
        bottom: -11px;
      }
    }
  }
}
.search-content {
  display: flex;
  flex-wrap: wrap;
  padding: 16px;
  padding-bottom: 0;
  margin-top: 16px;
  background-color: var(--back);
  .form-item {
    margin-bottom: 16px;
  }
  .form-item-box {
    display: flex;
    flex-wrap: wrap;
    flex: 1;
  }
  .action-btn-box {
    position: relative;
    width: 140px;
    text-align: center;
    .btn-locate {
      position: absolute;
      bottom: 16px;
    }
  }
}
</style>